﻿<%@ Page Culture="auto" UICulture="auto" Title="Input and output" ValidateRequest="false"
    Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="InputOutput.aspx.cs"
    Inherits="BM.Tools.WebControls.MForm.Example.Core.InputOutput" %>

<%@ Register Assembly="BM.Tools.WebControls.MForm" Namespace="BM.Tools.WebControls.MForm.Controls"
    TagPrefix="mf" %>
<%@ Register Assembly="BM.Tools.WebControls.MForm" Namespace="BM.Tools.WebControls.MForm.Controls.Additions"
    TagPrefix="add" %>
<%@ Register Assembly="BM.Tools.WebControls.MForm" Namespace="BM.Tools.WebControls.MForm.Controls.Modifiers"
    TagPrefix="mod" %>
<%@ Register TagPrefix="mftitle" Namespace="BM.Tools.WebControls.MForm.Controls.Titles"
    Assembly="BM.Tools.WebControls.MForm" %>
<asp:Content ContentPlaceHolderID="Demonstration" runat="server">
    <p>
        In the following demonstration, the MForm form interacts with a <code>TextBox</code>
        control, which is the source of form data input, and the dump for xml data output.
        Input and output work on button pressing.
    </p>
    <div class="Remark">
        <p>
            To make the example work, the <code>ValidateRequest</code> property of the page
            is set to false. Otherwise, the <code>TextBox</code> could not contain xml data.
            It is not advised to use such a code in real-life applications.</p>
    </div>
    <div style="margin: 2.5em">
        <span class="Important">XML input</span>
        <asp:TextBox ID="XmlTextBox" Text="<SimpleTest />" runat="server" Height="206px" TextMode="MultiLine" Width="100%" ></asp:TextBox>
    </div>
    <asp:Button ID="XmlTextButton" runat="server" ValidationGroup="none" Text="Click To provide MForm input"
        OnClick="XmlTextButtonClick" />
    <mf:RootValidator runat="server" ControlToValidate="Root1" />    
    <mf:Root ID="Root1" runat="server" >
        <UriMappings>
            <mf:UriMapping Prefix="xs" Namespace="http://www.w3.org/2001/XMLSchema"></mf:UriMapping>
            <mf:UriMapping Prefix="" Namespace=""></mf:UriMapping>
        </UriMappings>
        <Contents>
            <mf:Branch Name="SimpleTest" runat="server" >
                <Contents>
                    <mf:Leaf Name="LeafElement" runat="server">
                    </mf:Leaf>
                    <mf:Branch Name="BranchElement" runat="server">
                        <Contents>
                            <mf:Leaf Name="leafAttribute" runat="server" DataType="PositiveInteger" LeafType="Attribute"
                                MinOccurs="0" />
                        </Contents>
                    </mf:Branch>
                    <mf:Choice Name="Ch1" runat="server">
                        <Contents>
                            <mf:Leaf Name="SecondOption" runat="server" />
                            <mf:Branch Name="FirstOption" runat="server">
                                <Contents>
                                    <mf:Leaf Name="OptionText" runat="server" />
                                    <mf:Leaf Name="OptionNumber" runat="server" DataType="Integer" />
                                </Contents>
                            </mf:Branch>
                        </Contents>
                    </mf:Choice>
                </Contents>
            </mf:Branch>
        </Contents>
    </mf:Root>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="Description" runat="server">
    <p>
        What is important, when using MForm controls, is that they do not modify the input
        provided. Instead, the output is generated as a new XmlDocument.
    </p>
    <p>
        In most of the scenarios, the input xml will be provided to the <code>Root</code>
        control and the output will be taken from there. The input can be set using the
        <code>DataSource</code> or <code>DataSourceId</code> properties. See
        <asp:HyperLink NavigateUrl="~/Core/MFormItems.aspx#Root_InputOutput" ID="HyperLink1"
            runat="server">here</asp:HyperLink>
        for more details.
    </p>
    <div class="Section" id="Input">
        <mftitle:TitleControl runat="server" Text="Providing input" />
        <p>
            The content of the MForm is preserved on PostBack. It is not needed to load input
            xml to MForm on each page load. In case the <code>DataSource</code> property is
            set on Postback, it clears the previous PostBack data.
        </p>
        <div class="Remark">
            <p>
                It is planned to have all the <code>OffspringItem</code> controls accepting the
                <code>DataSource</code>. This would make it possible to create MForm out of more
                than one data source. Each <code>OffspringItem</code> already contains the property
                <code>DataSource</code>, which expects any <code>IXPathNavigable</code>. However
                currently the functionality is limited to the initial page run (setting data sources
                for inner items will not work on PostBack)</p>
        </div>
    </div>
    <div class="Section" id="Output">
        <mftitle:TitleControl runat="server" Text="Manipulating output" />
        <p>
            The output can be taken from the <code>Root</code> control using the <code>OutputXml</code>
            and <code>OutputXmlWithLeftNodes</code> properties.
        </p>
        <p>
            However, one can get the output fron an of <code>OffspringItem</code> controls,
            using the <code>GetOutputXml</code> and <code>GetOutputXmlWithLeftNodes</code> extension
            methods.
        </p>
    </div>
</asp:Content>
